﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FirstFloor.ModernUI.Presentation;
using System.ComponentModel;
using System.Xml;

namespace ModernWSPView.Pages
{
    public class PageListContentTypes2Model : INotifyPropertyChanged
    {
        public LinkCollection AllLinks { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void Load()
        {
            AllLinks = new LinkCollection();

            List<XmlElement> xeContentTypes = 
                AppModel.AppXmlDataSource
                    .Document
                    .SelectNodes("//ContentType")
                    .Cast<XmlElement>()
                    .ToList();

            foreach (XmlElement xe in xeContentTypes)
            {
                string url = string.Format(
                    "Pages/PageListFieldsOfContentTypes.xaml#{0}",
                    xe.Attributes["ID"].Value);
                AllLinks.Add(new Link()
                {
                    DisplayName = xe.Attributes["Name"].Value,
                    Source = new Uri(url, UriKind.RelativeOrAbsolute)
                });

            }

            OnPropertyChanged("AllLinks");
        }
    }
}
